package com.ruoyi.patrol.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PtLineSite;
import com.ruoyi.patrol.service.IPtLineSiteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡查线路和巡逻点位关联Controller
 * 
 * @author lkm
 * @date 2022-11-09
 */
@RestController
@RequestMapping("/patrol/linesite")
public class PtLineSiteController extends BaseController
{
    @Autowired
    private IPtLineSiteService ptLineSiteService;

    /**
     * 查询巡查线路和巡逻点位关联列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:site:list')")
    @GetMapping("/list")
    public TableDataInfo list(PtLineSite ptLineSite)
    {
        startPage();
        List<PtLineSite> list = ptLineSiteService.selectPtLineSiteList(ptLineSite);
        return getDataTable(list);
    }

    /**
     * 导出巡查线路和巡逻点位关联列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:site:export')")
    @Log(title = "巡查线路和巡逻点位关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PtLineSite ptLineSite)
    {
        List<PtLineSite> list = ptLineSiteService.selectPtLineSiteList(ptLineSite);
        ExcelUtil<PtLineSite> util = new ExcelUtil<PtLineSite>(PtLineSite.class);
        return util.exportExcel(list, "site");
    }

    /**
     * 获取巡查线路和巡逻点位关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:site:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ptLineSiteService.selectPtLineSiteById(id));
    }

    /**
     * 新增巡查线路和巡逻点位关联
     */
    @PreAuthorize("@ss.hasPermi('patrol:site:add')")
    @Log(title = "巡查线路和巡逻点位关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PtLineSite ptLineSite)
    {
        return toAjax(ptLineSiteService.insertPtLineSite(ptLineSite));
    }

    /**
     * 修改巡查线路和巡逻点位关联
     */
    @PreAuthorize("@ss.hasPermi('patrol:site:edit')")
    @Log(title = "巡查线路和巡逻点位关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtLineSite ptLineSite)
    {
        return toAjax(ptLineSiteService.updatePtLineSite(ptLineSite));
    }

    /**
     * 删除巡查线路和巡逻点位关联
     */
    @PreAuthorize("@ss.hasPermi('patrol:site:remove')")
    @Log(title = "巡查线路和巡逻点位关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ptLineSiteService.deletePtLineSiteByIds(ids));
    }
}
